using Common.Commands;
using Common.Commands.TrackLogCommands;
using Core.Domain.Model;
using Core.Infrastructure.CustomExceptions;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.TrackLogProcessors
{
    public class DeleteTrackLogProcessor : ICommandProcessor<DeleteTrackLog>
    {
        private readonly IRepository<TrackLog> _trackRepository;

        public DeleteTrackLogProcessor(IRepository<TrackLog> trackRepository)
        {
            _trackRepository = trackRepository;
        }

        public dynamic Process(DeleteTrackLog command)
        {
            var response = new WebApiResultResponse();

            var templete = _trackRepository.GetById(command.Id);

            if (templete == null)
                throw new DomainProcessException("Track Log not available");

            _trackRepository.Delete(templete.Id);
            response.IsSuccess = true;

            return response;
        }
    }
}
